package com.xmu.prcs.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.xmu.prcs.action.bean.KindBean;
import com.xmu.prcs.action.bean.KindKeBean;
import com.xmu.prcs.action.bean.KindShuBean;
import com.xmu.prcs.action.bean.LocationBean;
import com.xmu.prcs.action.bean.PlantInfoBean;
import com.xmu.prcs.action.bean.PlantLocationBean;
import com.xmu.prcs.action.bean.SubjectBean;
import com.xmu.prcs.entity.KindKe;
import com.xmu.prcs.entity.KindShu;
import com.xmu.prcs.entity.Subject;
import com.xmu.prcs.service.ClassificationManager;
import com.xmu.prcs.service.PlantInfoManager;
import com.xmu.prcs.util.DictionaryUtil;
import com.xmu.prcs.util.PageBean;
import com.xmu.prcs.util.ResultBean;

/**
 * 植物信息
 * @author frequent
 * @version 1.0,2012-3-20
 *
 */
@SuppressWarnings("serial")
public class PlantInfoAction extends BaseAction{

	private PlantInfoManager plantInfoManager;
	
	private ClassificationManager classificationManager;
	/**
	 * 植物信息
	 */
	private PlantInfoBean plant = new PlantInfoBean();
	
	/**
	 * 上传的文件
	 */
	private List<File> upload = new ArrayList<File>();
	
	/**
	 * 上传的文件名
	 */
	private List<String> uploadFileName = new ArrayList<String>();
	
	/**
	 * 上传的文件类型
	 */
	private List<String> uploadContentType = new ArrayList<String>();

	/**
	 * 分类科集合
	 */
	private List<KindKeBean> kindKe;
	
	/**
	 * 专题名
	 */
	private List<SubjectBean> subjects;
	
	/**
	 * 分页封装类
	 */
	private ResultBean pagePlant;
	
	/**
	 * 与界面交互的分页封装类
	 */
	private PageBean page = new PageBean();
	
	/**
	 * 界面上显示的页码
	 */
	private List<String> pageNumber;
	
	/**
	 * 翻页
	 * -1表示向前翻页
	 * 0表示不翻页
	 * 1表示向后翻页
	 */
	private int move = 0;
	
	/**
	 * 显示的植物列表
	 */
	private List<PlantInfoBean> plantList;
	
	/**
	 * 植物名
	 */
	private String plantName;
	
	/**
	 * 某植物的地理位置
	 */
	private List<LocationBean> locations;
	
	/**
	 * 分类属bean
	 */
	private KindShuBean kindShu;
	
	/**
	 * 完成新增或修改功能
	 */
//	private int addOrEdit;
	
	/**
	 * 植物分类科的id
	 */
	private String idKindKe;
	
	/**
	 * 植物主题的id
	 */
	private String idSubject;
	
	/**
	 * 封装专题的分页结构
	 */
	private ResultBean subjectPage;
	
	/**
	 * 专题列表
	 */
	private List<SubjectBean> subjectList;
	
	/**
	 * 专题页面bean
	 */
	private SubjectBean subjectbean;
	
	/**
	 * 判断是增加还是修改页面
	 * 1为增加
	 * 2为修改
	 */
	private int addOrEdit;
	
	/**
	 * 分类属的id
	 */
	private String idKindShu;
	
	/**
	 * 分页时的最后一页
	 */
	private String endPage;
	
	/**
	 * 判断是分类科还是属
	 * 1为科
	 * 2为属
	 */
	private int keOrShu;
	
	/**
	 * 分类名
	 */
	private String kindName;
	
	/**
	 * 分类bean
	 */
	private List<KindBean> kindList;
	
	/**
	 * 删除专题结果
	 */
	private int deleteSubjectResult;
	
	private List<PlantLocationBean> plantLocation;
	
	private int deleteKindResult;
	
	private int plantId;
	
	public PlantInfoManager getPlantInfoManager() {
		return plantInfoManager;
	}

	public void setPlantInfoManager(PlantInfoManager plantInfoManager) {
		this.plantInfoManager = plantInfoManager;
	}

	public ClassificationManager getClassificationManager() {
		return classificationManager;
	}

	public void setClassificationManager(ClassificationManager classificationManager) {
		this.classificationManager = classificationManager;
	}

	public PlantInfoBean getPlant() {
		return plant;
	}

	public void setPlant(PlantInfoBean plant) {
		this.plant = plant;
	}

	
	public List<File> getUpload() {
		return upload;
	}

	public void setUpload(List<File> upload) {
		this.upload = upload;
	}

	public List<String> getUploadFileName() {
		return uploadFileName;
	}

	public void setUploadFileName(List<String> uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public List<String> getUploadContentType() {
		return uploadContentType;
	}

	public void setUploadContentType(List<String> uploadContentType) {
		this.uploadContentType = uploadContentType;
	}

	public List<KindKeBean> getKindKe() {
		return kindKe;
	}

	public void setKindKe(List<KindKeBean> kindKe) {
		this.kindKe = kindKe;
	}

	public List<SubjectBean> getSubjects() {
		return subjects;
	}

	public void setSubjects(List<SubjectBean> subjects) {
		this.subjects = subjects;
	}

	public ResultBean getPagePlant() {
		return pagePlant;
	}

	public void setPagePlant(ResultBean pagePlant) {
		this.pagePlant = pagePlant;
	}

	public List<String> getPageNumber() {
		return pageNumber;
	}

	public void setPageNumber(List<String> pageNumber) {
		this.pageNumber = pageNumber;
	}
	public PageBean getPage() {
		return page;
	}

	public void setPage(PageBean page) {
		this.page = page;
	}
	
	public List<PlantInfoBean> getPlantList() {
		return plantList;
	}

	public void setPlantList(List<PlantInfoBean> plantList) {
		this.plantList = plantList;
	}

	public String getPlantName() {
		return plantName;
	}

	public void setPlantName(String plantName) {
		this.plantName = plantName;
	}

	public List<LocationBean> getLocations() {
		return locations;
	}

	public void setLocations(List<LocationBean> locations) {
		this.locations = locations;
	}

	public KindShuBean getKindShu() {
		return kindShu;
	}

	public void setKindShu(KindShuBean kindShu) {
		this.kindShu = kindShu;
	}

//	public int getAddOrEdit() {
//		return addOrEdit;
//	}
//
//	public void setAddOrEdit(int addOrEdit) {
//		this.addOrEdit = addOrEdit;
//	}

	public String getIdKindKe() {
		return idKindKe;
	}

	public void setIdKindKe(String idKindKe) {
		this.idKindKe = idKindKe;
	}

	public String getIdSubject() {
		return idSubject;
	}

	public void setIdSubject(String idSubject) {
		this.idSubject = idSubject;
	}

	public ResultBean getSubjectPage() {
		return subjectPage;
	}

	public void setSubjectPage(ResultBean subjectPage) {
		this.subjectPage = subjectPage;
	}

	public List<SubjectBean> getSubjectList() {
		return subjectList;
	}

	public void setSubjectList(List<SubjectBean> subjectList) {
		this.subjectList = subjectList;
	}

	public int getMove() {
		return move;
	}

	public void setMove(int move) {
		this.move = move;
	}

	public SubjectBean getSubjectbean() {
		return subjectbean;
	}

	public void setSubjectbean(SubjectBean subjectbean) {
		this.subjectbean = subjectbean;
	}

	public int getAddOrEdit() {
		return addOrEdit;
	}

	public void setAddOrEdit(int addOrEdit) {
		this.addOrEdit = addOrEdit;
	}

	public String getIdKindShu() {
		return idKindShu;
	}

	public void setIdKindShu(String idKindShu) {
		this.idKindShu = idKindShu;
	}

	public String getEndPage() {
		return endPage;
	}

	public void setEndPage(String endPage) {
		this.endPage = endPage;
	}

	public int getKeOrShu() {
		return keOrShu;
	}

	public void setKeOrShu(int keOrShu) {
		this.keOrShu = keOrShu;
	}

	public String getKindName() {
		return kindName;
	}

	public void setKindName(String kindName) {
		this.kindName = kindName;
	}

	public List<KindBean> getKindList() {
		return kindList;
	}

	public void setKindList(List<KindBean> kindList) {
		this.kindList = kindList;
	}

	public List<PlantLocationBean> getPlantLocation() {
		return plantLocation;
	}

	public void setPlantLocation(List<PlantLocationBean> plantLocation) {
		this.plantLocation = plantLocation;
	}

	public int getDeleteSubjectResult() {
		return deleteSubjectResult;
	}

	public void setDeleteSubjectResult(int deleteSubjectResult) {
		this.deleteSubjectResult = deleteSubjectResult;
	}


	public int getDeleteKindResult() {
		return deleteKindResult;
	}

	public void setDeleteKindResult(int deleteKindResult) {
		this.deleteKindResult = deleteKindResult;
	}

	public int getPlantId() {
		return plantId;
	}

	public void setPlantId(int plantId) {
		this.plantId = plantId;
	}

	/**
	 * 跳转到增加植物的页面
	 * @return
	 */
	public String toAddPlant(){
		kindKe = plantInfoManager.getAllKindKe();
		subjects = plantInfoManager.getAllSubjectName();
//		addOrEdit = DictionaryUtil.EDIT_OR_ADD_ADD;
		return SUCCESS;
	}
	
	/**
	 * 跳转到修改植物信息页面
	 * @return
	 */
	public String toModifyPlant(){
		try {
    		plantName = new String(plantName.getBytes("ISO8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return INPUT;
		}
		kindKe = plantInfoManager.getAllKindKe();
		subjects = plantInfoManager.getAllSubjectName();
		
		plant = plantInfoManager.getPlantByName(plantName);
    	locations = new ArrayList<LocationBean>();
    	if(plant.getLongitude() != null && plant.getLongitude().size() != 0){
    		LocationBean bean = new LocationBean();
    		for(int i = 0; i < plant.getLongitude().size(); i++){
    			bean.setLongtitude(plant.getLongitude().get(i));
    			bean.setLatitude(plant.getLatitude().get(i));
    			locations.add(bean);
    		}
    	}
    	KindShu shu = plantInfoManager.getKindShuByProperty(plant.getKindShu());
    	kindShu = new KindShuBean();
    	kindShu.setValue(shu.getIdKindShu().toString());
    	kindShu.setKindShuName(shu.getKindName());
    	
    	KindKe ke = plantInfoManager.getKindKeByProperty(plant.getKindKe());
    	idKindKe = ke.getIdKindKe().toString();
    	
    	Subject subject = plantInfoManager.getSubjectByName(plant.getSubject());
    	idSubject = subject.getIdSubject().toString();
    	
//    	addOrEdit = DictionaryUtil.EDIT_OR_ADD_EDIT;
    	
		return SUCCESS;
	}
	
	/**
	 * 修改植物信息
	 * @return
	 */
	public String modifyPlant(){
		String fileName;// 上传植物图像
		if(plant.getImagePaths() == null || plant.getImagePaths().size() == 0){
			List<String> images = new ArrayList<String>();
			if (upload == null || upload.size() == 0) {
				fileName = DictionaryUtil.DEFAULT_PHOTO;
				images.add(fileName);
				System.out.println("file is empty");
			} else {
				for (int i = 0; i < upload.size(); i++) {
					fileName = this.uploadImage(i);
					if(!fileName.equals("")){
						images.add(fileName.replace('\\', '/'));
					}
				}
			}
			plant.setImagePaths(images);
		}else{
			
			for (int i = 0; i < upload.size(); i++) {
				fileName = this.uploadImage(i);
				if(!fileName.equals("") && !fileName.equals(DictionaryUtil.DEFAULT_PHOTO)){
					plant.getImagePaths().add(fileName.replace('\\', '/'));
				}
			}
		}
		
		plantInfoManager.modifyPlant(plant);
		System.out.println("end of modify");
		return SUCCESS;
	}
	
	/**
	 * 增加植物
	 * @return
	 */
	public String addPlant(){
		try {
			// 可以同时上传多张图片
			List<String> images = new ArrayList<String>();
			String fileName;// 上传植物图像
			if (upload == null || upload.size() == 0) {
				fileName = DictionaryUtil.DEFAULT_PHOTO;
				images.add(fileName);
				System.out.println("file is empty");
			} else {
				for (int i = 0; i < upload.size(); i++) {
					fileName = this.uploadImage(i);
					if(!fileName.equals("")){
						images.add(fileName.replace('\\', '/'));
					}
				}
			}

			plant.setImagePaths(images);
			plantInfoManager.addPlant(plant);
			System.out.println("add end");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return SUCCESS;
	}
	
	   /** 
     * 上传单个图片，返回图片存储文件名
     * @return 
     */  
    public String uploadImage(int i){  
    	if(upload.get(i) == null || uploadFileName.get(i) == null || uploadFileName.get(i).equals("")){
    		System.out.println("file" + i + ": is empty");
    		if(i == 0){
    			return DictionaryUtil.DEFAULT_PHOTO;
    		}
    		return "";
    	}
    	
    	try {
    		
    		String basePath = this.getRequest().getSession().getServletContext().getRealPath("") + "\\";
    		String storeFileName = this.createNewFileName(i);
    		String fileName = basePath + storeFileName;
    		String backup = "d:\\" + storeFileName; //备份位置
    		//防止文件名重复
    		int add = 1;
    		while(new File(fileName).exists()){
    			fileName += add;
    			add++;
    		}
			FileOutputStream fos = new FileOutputStream(fileName);
			FileOutputStream backupfos = new FileOutputStream(backup);
			InputStream is = new FileInputStream(upload.get(i));//页面传进来的文件
			byte[] buffer = new byte[8192]; //每次读写8K字节
			int count = 0;
			while((count = is.read(buffer)) > 0){
				fos.write(buffer, 0, count);
				backupfos.write(buffer, 0, count);
			}
			fos.close();
			backupfos.close();
			is.close();
			return storeFileName;
		}catch(NullPointerException e){
			e.printStackTrace();
			return DictionaryUtil.DEFAULT_PHOTO;
		}
    	catch (FileNotFoundException e) {
			e.printStackTrace();
			return DictionaryUtil.DEFAULT_PHOTO;
		} catch (IOException e) {
			e.printStackTrace();
			return DictionaryUtil.DEFAULT_PHOTO;
		}
    }  
    
    /**
     * 得到新的文件名
     * @return
     */
    public String createNewFileName(int i){
    	Date date = new Date();
    	
		String basePath = this.getRequest().getSession().getServletContext().getRealPath("") + "\\";
    	File filedir = new File(basePath + DictionaryUtil.UPLOAD_PLANT_IMAGE_PATH);
    	if(!filedir.exists()){
    		filedir.mkdir();
    	}
    	String filename = DictionaryUtil.UPLOAD_PLANT_IMAGE_PATH + "img";
    	filename += date.getTime();
    	System.out.println("uploadfilename:" + upload.get(i).getName());
//    	System.out.println("uploadfilename:" + upload.getName());
    	//获得上传文件的后缀名
    	filename += uploadFileName.get(i).substring(uploadFileName.get(i).indexOf("."));
//    	filename += upload.getName().substring(upload.getName().indexOf("."));
    	return filename;
    }
    
    /**
     * 得到植物分页列表
     * @return
     */
    public String listPlant4Page(){
    	
    	if(page != null){
    		System.out.println("currentpage" + page.getCurrentPage()+",countPage:"+page.getCountPage());
    	}
    	if(plantName != null){
    		try {
    			plantName = new String(plantName.getBytes("ISO8859-1"),"UTF-8");
    		} catch (UnsupportedEncodingException e) {
    			e.printStackTrace();
    			return INPUT;
    		}
    		System.out.println("plantName: " + plantName);
    	}
    	if(move == 1){
    		if(Integer.parseInt(endPage) == 0 ){
    			page.setCurrentPage(page.getCurrentPage() + 9);
    		}
    	}else if(move == -1){
    		if(page.getCurrentPage() > 9){
    			page.setCurrentPage(page.getCurrentPage() - 9);
    		}
    	}
//    	pageNumber = (List<String>)this.getSession().getAttribute("page");
//    	
//    	if(pageNumber != null && move != 0){//要翻页
//    		page = new PageBean();
//    		if(move == -1){
//    			if(Integer.parseInt(pageNumber.get(0)) > 10){
//    				page.setCurrentPage(Integer.parseInt(pageNumber.get(0)) - 10);
//    			}else{
//    				page.setCurrentPage(1);
//    			}
//    		}else if(move == 1){
//    			if(Integer.parseInt(pageNumber.get(pageNumber.size() - 1)) == 0){
//    				page.setCurrentPage(Integer.parseInt(pageNumber.get(pageNumber.size() - 2)));
//    			}
//    			else{
//    				page.setCurrentPage(Integer.parseInt(pageNumber.get(0)));
//    			}
//    		}
//    	}
    	
    	pagePlant = plantInfoManager.getPlant4Page(page, idSubject, idKindShu, plantName);
    	plantList = (List<PlantInfoBean>)pagePlant.getContent();
    	for(PlantInfoBean p : plantList){
    		System.out.println("image:" + p.getImagePaths().get(0));
    	}
    	//处理界面显示页码，从当前页码开始
    	pageNumber = new ArrayList<String>();
    	if(pagePlant.getPage().getCountPage() - pagePlant.getPage().getCurrentPage() + 1 <= 10){//最多显示10个页码
    		for(int i = pagePlant.getPage().getCurrentPage() ; i <= pagePlant.getPage().getCountPage(); i++){
    			System.out.println(i);
    			pageNumber.add(Integer.toString(i));
    		}
    	}else{
    		for(int i = pagePlant.getPage().getCurrentPage(); i <= pagePlant.getPage().getCurrentPage() + 9; i++){
    			pageNumber.add(Integer.toString(i));
    		}
    		pageNumber.add("0");//表示省略号
    	}
//    	this.getSession().setAttribute("page", pageNumber);
    	
    	return SUCCESS;
    }

    public String showPlantInfo(){
    	try {
    		plantName = new String(plantName.getBytes("ISO8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return INPUT;
		}
    	plant = plantInfoManager.getPlantByName(plantName);
    	locations = new ArrayList<LocationBean>();
    	if(plant.getLongitude() != null && plant.getLongitude().size() != 0){
    		LocationBean bean = new LocationBean();
    		for(int i = 0; i < plant.getLongitude().size(); i++){
    			bean.setLongtitude(plant.getLongitude().get(i));
    			bean.setLatitude(plant.getLatitude().get(i));
    			locations.add(bean);
    		}
    	}
    	return SUCCESS;
    }
    
    /**
     * 删除植物
     * @return
     */
    public String deletePlant(){
    	plantInfoManager.deletePlant(plantId);
    	return SUCCESS;
    }
    
    /**
     * 收藏植物
     * @return
     */
    public String collectPlant(){
    	try {
    		plantName = new String(plantName.getBytes("ISO8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return INPUT;
		}
    	return SUCCESS;
    }
    
    /**
     * 按分页效果列出专题列表
     * @return
     */
    public String listSubject4Page(){
    	if(move == 1){
    		if(Integer.parseInt(endPage) == 0 ){
    			page.setCurrentPage(page.getCurrentPage() + 9);
    		}
    	}else if(move == -1){
    		if(page.getCurrentPage() > 9){
    			page.setCurrentPage(page.getCurrentPage() - 9);
    		}
    	}
    	
    	subjectPage = plantInfoManager.getSubject4Page(page);
    	subjectList = (List<SubjectBean>)subjectPage.getContent();
    	
    	//处理界面显示页码，从当前页码开始
    	pageNumber = new ArrayList<String>();
    	if(subjectPage.getPage().getCountPage() - subjectPage.getPage().getCurrentPage() + 1 <= 10){//最多显示10个页码
    		for(int i = subjectPage.getPage().getCurrentPage() ; i <= subjectPage.getPage().getCountPage(); i++){
    			System.out.println(i);
    			pageNumber.add(Integer.toString(i));
    		}
    	}else{
    		for(int i = subjectPage.getPage().getCurrentPage(); i < subjectPage.getPage().getCurrentPage() + 9; i++){
    			pageNumber.add(Integer.toString(i));
    		}
    		pageNumber.add("0");//表示省略号
    		pageNumber.add(Integer.toString(subjectPage.getPage().getCountPage()));
    	}
    	deleteSubjectResult = 0;
    	return SUCCESS;
    }
    
    /**
     * 删除某个专题
     * @return
     */
    public String deleteSubject(){
    	System.out.println(idSubject);
    	plantInfoManager.deleteSubject(idSubject);
    	System.out.println("delete success");
    	this.listSubject4Page();
    	deleteSubjectResult = 1;
    	System.out.println("deleteSubjectResult:" + deleteSubjectResult );
    	return SUCCESS;
    }
    
    /**
     * 列出专题下的所有植物
     * @return
     */
    public String listPlantOfSubject(){
    	if(page != null){
    		System.out.println("currentpage" + page.getCurrentPage());
    	}
    	pageNumber = (List<String>)this.getSession().getAttribute("page");
    	
    	if(pageNumber != null && move != 0){//要翻页
    		page = new PageBean();
    		if(move == -1){
    			if(Integer.parseInt(pageNumber.get(0)) > 10){
    				page.setCurrentPage(Integer.parseInt(pageNumber.get(0)) - 10);
    			}else{
    				page.setCurrentPage(1);
    			}
    		}else if(move == 1){
    			if(Integer.parseInt(pageNumber.get(pageNumber.size() - 1)) == 0){
    				page.setCurrentPage(Integer.parseInt(pageNumber.get(pageNumber.size() - 2)));
    			}
    			else{
    				page.setCurrentPage(Integer.parseInt(pageNumber.get(0)));
    			}
    		}
    	}
    	System.out.println("idSubject:" + idSubject);
    	pagePlant = plantInfoManager.getPlant4PageBySubject(Integer.parseInt(idSubject), page);
    	plantList = (List<PlantInfoBean>)pagePlant.getContent();
    	for(PlantInfoBean p : plantList){
    		System.out.println("image:" + p.getImagePaths().get(0));
    	}
    	//处理界面显示页码，从当前页码开始
    	pageNumber = new ArrayList<String>();
    	if(pagePlant.getPage().getCountPage() - pagePlant.getPage().getCurrentPage() + 1 <= 10){//最多显示10个页码
    		for(int i = pagePlant.getPage().getCurrentPage() ; i <= pagePlant.getPage().getCountPage(); i++){
    			System.out.println(i);
    			pageNumber.add(Integer.toString(i));
    		}
    	}else{
    		for(int i = pagePlant.getPage().getCurrentPage(); i <= pagePlant.getPage().getCurrentPage() + 9; i++){
    			pageNumber.add(Integer.toString(i));
    		}
    		pageNumber.add("0");//表示省略号
    	}
    	this.getSession().setAttribute("page", pageNumber);
    	
    	return SUCCESS;
    }
    
    /**
     * 跳转到增加专题页面
     * @return
     */
    public String toAddSubject(){
    	addOrEdit = 1;
    	return SUCCESS;
    }
    
    /**
     * 增加专题
     * @return
     */
    public String addSubject(){
    	System.out.println("subject name:" + subjectbean.getSubjectName()
    			+ ", info:" + subjectbean.getSubjectInfo());
    	plantInfoManager.addSubject(subjectbean);
    	return SUCCESS;
    }
    
    /**
     * 跳转到修改专题信息
     * @return
     */
    public String toModifySubject(){
    	System.out.println("idSubject:" + idSubject);
    	subjectbean = plantInfoManager.getSubjectById(Integer.parseInt(idSubject));
    	addOrEdit = 2;
    	return SUCCESS;
    }
    
    /**
     * 修改专题
     * @return
     */
    public String modifySubject(){
    	plantInfoManager.modifySubject(subjectbean);
    	return SUCCESS;
    }
    
    /**
     * 列出分类，科或属
     * @return
     */
    public String listKind(){
		if (kindName != null && !kindName.equals("")) {
			try {
				kindName = new String(kindName.getBytes("ISO8859-1"), "UTF-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
				return INPUT;
			}
		}
    	if(move == 1){
    		if(Integer.parseInt(endPage) == 0 ){
    			page.setCurrentPage(page.getCurrentPage() + 9);
    		}
    	}else if(move == -1){
    		if(page.getCurrentPage() > 9){
    			page.setCurrentPage(page.getCurrentPage() - 9);
    		}
    	}
    	
    	if(keOrShu == 1){//科分类
    		pagePlant = plantInfoManager.getKindKe4Page(page, kindName);
    	}else if(keOrShu == 2){//属分类
    		pagePlant = plantInfoManager.getKindShu4Page(page, kindName, idKindKe);
    	}
    	kindList = (List<KindBean>)pagePlant.getContent();
    	
    	//处理界面显示页码，从当前页码开始
    	pageNumber = new ArrayList<String>();
    	if(pagePlant.getPage().getCountPage() - pagePlant.getPage().getCurrentPage() + 1 <= 10){//最多显示10个页码
    		for(int i = pagePlant.getPage().getCurrentPage() ; i <= pagePlant.getPage().getCountPage(); i++){
    			System.out.println(i);
    			pageNumber.add(Integer.toString(i));
    		}
    	}else{
    		for(int i = pagePlant.getPage().getCurrentPage(); i <= pagePlant.getPage().getCurrentPage() + 9; i++){
    			pageNumber.add(Integer.toString(i));
    		}
    		pageNumber.add("0");//表示省略号
    	}
    	return SUCCESS;
    }
    
    /**
     * 地图植物定位
     * @return
     */
    public String mapSearchPlant(){
    	plantLocation = plantInfoManager.getPlantAndLocation();
    	return SUCCESS;
    }
    
    /**
     * 删除分类科
     * @return
     */
    public String deleteKindke(){
    	int kind = 0;
    	if(idKindKe != null && !idKindKe.equals("")){
    		kind = Integer.parseInt(idKindKe);
    	}
    	plantInfoManager.deleteKindKe(kind);
    	this.listKindKe();
    	deleteKindResult = 1;
    	return SUCCESS;
    }
    
    /**
     * 删除分类属
     * @return
     */
    public String deleteKindShu(){
    	int kind = 0;
    	if(idKindShu != null && !idKindShu.equals("")){
    		kind = Integer.parseInt(idKindShu);
    	}
    	plantInfoManager.deleteKindShu(kind);
    	this.listKindShu();
    	deleteKindResult = 2;
    	return SUCCESS;
    }
    
    /**
     * 按分页列出科分类
     * @return
     */
    public String listKindKe(){
    	if(move == 1){
    		if(Integer.parseInt(endPage) == 0 ){
    			page.setCurrentPage(page.getCurrentPage() + 9);
    		}
    	}else if(move == -1){
    		if(page.getCurrentPage() > 9){
    			page.setCurrentPage(page.getCurrentPage() - 9);
    		}
    	}

    	pagePlant = plantInfoManager.getKindKe4Page(page, kindName);
    	kindList = (List<KindBean>)pagePlant.getContent();
    	
    	//处理界面显示页码，从当前页码开始
    	pageNumber = new ArrayList<String>();
    	if(pagePlant.getPage().getCountPage() - pagePlant.getPage().getCurrentPage() + 1 <= 10){//最多显示10个页码
    		for(int i = pagePlant.getPage().getCurrentPage() ; i <= pagePlant.getPage().getCountPage(); i++){
    			System.out.println(i);
    			pageNumber.add(Integer.toString(i));
    		}
    	}else{
    		for(int i = pagePlant.getPage().getCurrentPage(); i <= pagePlant.getPage().getCurrentPage() + 9; i++){
    			pageNumber.add(Integer.toString(i));
    		}
    		pageNumber.add("0");//表示省略号
    	}
    	return SUCCESS;
    }
    
    /**
     * 按分页列出属分类
     * @return
     */
    public String listKindShu(){
    	if(move == 1){
    		if(Integer.parseInt(endPage) == 0 ){
    			page.setCurrentPage(page.getCurrentPage() + 9);
    		}
    	}else if(move == -1){
    		if(page.getCurrentPage() > 9){
    			page.setCurrentPage(page.getCurrentPage() - 9);
    		}
    	}

    	pagePlant = plantInfoManager.getKindShu4Page(page, kindName, idKindKe);
    	
    	kindList = (List<KindBean>)pagePlant.getContent();
    	
    	//处理界面显示页码，从当前页码开始
    	pageNumber = new ArrayList<String>();
    	if(pagePlant.getPage().getCountPage() - pagePlant.getPage().getCurrentPage() + 1 <= 10){//最多显示10个页码
    		for(int i = pagePlant.getPage().getCurrentPage() ; i <= pagePlant.getPage().getCountPage(); i++){
    			System.out.println(i);
    			pageNumber.add(Integer.toString(i));
    		}
    	}else{
    		for(int i = pagePlant.getPage().getCurrentPage(); i <= pagePlant.getPage().getCurrentPage() + 9; i++){
    			pageNumber.add(Integer.toString(i));
    		}
    		pageNumber.add("0");//表示省略号
    	}
    	return SUCCESS;
    }
}

